package com.buba.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import common.R;
import entity.salary.dto.AccountDto;
import entity.staff.dto.saveAccountDto;
import entity.staff.dto.updateAccSecurityDto;
import entity.staff.dto.withAccumPerDto;
import entity.staff.dto.withSocialPerDto;
import entity.staff.vo.accountingVo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.security.SecureRandom;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.buba.service.AccountingService;
import entity.staff.Accounting;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import utils.PageResult;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-03-14
 */
@RestController
@RequestMapping("/accounting")
public class AccountingController {

    @Resource
    private AccountingService accountingService;

    /* *
     * @Author: beisheng
     * @Descriprion: 根据人员ID查询当前人员信息
     * @Date: 2023/3/31 14:06
     * @Return: entity.staff.Accounting
     * @Param: [accId]
     */

    @GetMapping("/selAccById")
    public Accounting selAccById(@RequestBody Integer accId){
        return accountingService.getById(accId);
    }
    /* *
     * @Author: beisheng
     * @Descriprion: 办理增员
     * @Date: 2023/3/20 19:37
     * @Return: void
     * @Param: [saveAccountDto]
     */

    @PostMapping("/updateAccSocialAndAccum")
    void updateAccSocialAndAccum(AccountDto saveAccountDto){
        Accounting accounting = new Accounting();
        accounting.setSecurityId(saveAccountDto.getSocialId());
        accounting.setAccumulationId(saveAccountDto.getAccumId());
        accounting.setInsurancefileId(saveAccountDto.getInsuranceId());
        accountingService.update(accounting,new QueryWrapper<Accounting>().eq("delete_flag",0).eq("oz_id",saveAccountDto.getAccId()));
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据人员参保状态模糊查分页查询人员信息
     * @Date: 2023/3/20 19:08
     * @Return: common.R
     * @Param: [status]
     */

    @PostMapping("/selAccountBystatus")
    public R selAccountBystatus(@RequestBody Map<String,Object> map){
        PageResult pageResult = accountingService.selAccountBystatus(map);
        return R.success(pageResult);
    }

    @GetMapping("/selAllAccountBystatus")
    public R selAllAccountBystatus(){
       List<accountingVo> accountingVos = accountingService.selAllAccountBystatus();
        return R.success(accountingVos);
    }
    /* *
     * @Author: beisheng
     * @Descriprion: 修改人员关联社保档案ID
     * @Date: 2023/3/20 14:57
     * @Return: void
     * @Param: [socialId, ozId]
     */
    @PostMapping("/updateInsuranceFileId")
    void updateInsuranceFileId(@RequestBody Map<String,Integer> map){
        Integer socialId = map.get("socialId");
        Integer ozId = map.get("ozId");
        Accounting accounting = new Accounting();
        accounting.setInsurancefileId(socialId);
        accounting.setInsuranceStatus(1);
        accountingService.update(accounting,new QueryWrapper<Accounting>().eq("delete_flag",0).eq("oz_id",ozId));
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 查询当前社保关联的人员是否绑定参保档案
     * @Date: 2023/3/20 13:36
     * @Return: java.util.List<entity.staff.Accounting>
     * @Param: [saId]
     */

    @PostMapping("/selInsurancefile")
    List<Accounting> selInsurancefile(@RequestBody Integer saId){
        return accountingService.selInsurancefile(saId);
}

    /* *
     * @Author: beisheng
     * @Descriprion: 查询当前公积金关联的人员是否绑定参保档案
     * @Date: 2023/3/20 13:36
     * @Return: java.util.List<entity.staff.Accounting>
     * @Param: [saId]
     */

    @PostMapping("/selInsurancefiles")
    List<Accounting> selInsurancefiles(@RequestBody Integer saId){
        return accountingService.selInsurancefiles(saId);
    }
    /* *
     * @Author: beisheng
     * @Descriprion: 批量将用户解绑社保方案
     * @Date: 2023/3/17 13:47
     * @Return: void
     * @Param: [ids]
     */

    @PostMapping("/updateACCScheme")
    public void updateACCScheme(@RequestBody List<String> ids){
        accountingService.updateACCScheme(ids);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 再更改方案关联人员的时候给员工解绑或者绑定方案
     * @Date: 2023/3/19 20:28
     * @Return: void
     * @Param: [updateAccSecurityDto]
     */

    @PostMapping("/updateAccum")
    void updateAccum(@RequestBody updateAccSecurityDto updateAccSecurityDto){
        accountingService.updateAccum(updateAccSecurityDto);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 再更改方案关联人员的时候给员工解绑或者绑定方案
     * @Date: 2023/3/19 20:28
     * @Return: void
     * @Param: [updateAccSecurityDto]
     */

    @PostMapping("/updateAccSecurity")
    void updateAccSecurity(@RequestBody updateAccSecurityDto updateAccSecurityDto){
        accountingService.updateAccSecurity(updateAccSecurityDto);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 给员工绑定社保方案
     * @Date: 2023/3/17 9:42
     * @Return: common.R
     * @Param: [saveAccountDto]
     */

    @PostMapping("/saveAccountToSocial")
    public R saveAccountToSocial(@RequestBody saveAccountDto saveAccountDto){
        accountingService.saveAccountToSocial(saveAccountDto);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 给员工绑定公积金方案
     * @Date: 2023/3/17 9:42
     * @Return: common.R
     * @Param: [saveAccountDto]
     */

    @PostMapping("/saveAccountToAccum")
    public R saveAccountToAccum(@RequestBody saveAccountDto saveAccountDto){
        accountingService.saveAccountToAccum(saveAccountDto);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 给员工绑定公积金方案
     * @Date: 2023/3/17 9:42
     * @Return: common.R
     * @Param: [saveAccountDto]
     */

    @PostMapping("/saveAccountToAccumulation")
    public R saveAccountToAccumulation(@RequestBody saveAccountDto saveAccountDto){
        accountingService.saveAccountToAccumulation(saveAccountDto);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 批量将用户解绑公积金方案
     * @Date: 2023/3/17 13:47
     * @Return: void
     * @Param: [ids]
     */

    @PostMapping("/updateAccumScheme")
    void updateAccumScheme(@RequestBody List<String> ids){
        accountingService.updateAccumScheme(ids);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据公积金方案id分页模糊查询关联的人员
     * @Date: 2023/3/16 10:56
     * @Return: java.util.List<entity.staff.Accounting>
     * @Param: [socialPerDto]
     */

    @PostMapping("/selstaffByAccum")
    PageResult selstaffByAccum(@RequestBody withAccumPerDto accumPerDto){
        return accountingService.selstaffByAccum(accumPerDto);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据多个用户id查询用户数据
     * @Date: 2023/3/15 19:57
     * @Return: java.util.List<entity.staff.Accounting>
     * @Param: [splitLiss]
     */

    @PostMapping("/selstaffByIds")
    public List<Accounting> selstaffByIds(@RequestBody List<String> splitLiss){
        return accountingService.selstaffByIds(splitLiss);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据社保方案id分页模糊查询关联的人员
     * @Date: 2023/3/16 10:56
     * @Return: java.util.List<entity.staff.Accounting>
     * @Param: [socialPerDto]
     */

    @PostMapping("/selstaffBySocial")
    public PageResult selstaffBySocial(@RequestBody withSocialPerDto socialPerDto){
        return accountingService.selstaffBySocial(socialPerDto);
    }

    @PostMapping("/selAllPeopleHasNoSocial")
    public R selAllPeopleHasNoSocial(@RequestBody List<Integer> ids){
        List<Accounting> list = accountingService.selAllPeopleHasNoSocial(ids);
        return R.success(list);
    }

    /**
     * 功能描述: 新增或更新
     *
     * @param accounting
     * @return
     * @throws
     * @Author: zl
     */
    @PostMapping("/save")
    public R save(@RequestBody Accounting accounting) {
        accountingService.saveOrUpdate(accounting);
        return R.success();
    }

    /**
     * 功能描述: 删除
     *
     * @param id
     * @return
     * @throws
     * @Author: zl
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        accountingService.removeById(id);
        return R.success();
    }

    /**
     * 功能描述: 批量删除
     *
     * @param ids
     * @return
     * @throws
     * @Author: zl
     */
    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<Integer> ids) {
        accountingService.removeByIds(ids);
        return R.success();
    }

    /**
     * 功能描述: 全查
     *
     * @param
     * @return
     * @throws
     * @Author: zl
     */
    @GetMapping("/findAll")
    public R findAll() {
        return R.success(accountingService.list());
    }

    /**
     * 功能描述: 单查
     *
     * @param id
     * @return
     * @throws
     * @Author: zl
     */
    @GetMapping("/findOne/{id}")
    public R findOne(@PathVariable Integer id) {
        return R.success(accountingService.getById(id));
    }

    /**
     * 功能描述: 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws
     * @Author: zl
     * @Date:   2022/7/28 19:15
     */
    @GetMapping("/findPage")
    public R findPage(@RequestParam Integer pageNum,
                                 @RequestParam Integer pageSize) {
        QueryWrapper<Accounting> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return R.success(accountingService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 分页查询参保人员信息以及人员关联社保公积金基本信息
     * @Date: 2023/3/21 16:37
     * @Return: common.R
     * @Param: [map]
     */

    @PostMapping("/selAccAndSocialAndAccum")
    public R selAccAndSocialAndAccum(@RequestBody Map<String,Integer> map){
        PageResult pageResult = accountingService.selAccAndSocialAndAccum(map);
        return R.success(pageResult);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 办理减员,停保
     * @Date: 2023/3/21 20:05
     * @Return: common.R
     * @Param: [accId]
     */

    @GetMapping("/suspension/{accId}")
    public R Suspension(@PathVariable("accId") Integer accId){
        accountingService.Suspension(accId);
        return R.success();
    }

}
